<?php

/**
 * Pwiff - PHP SWF Library
 *
 * LICENSE
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 *
 * @package    Pwiff
 * @subpackage Tags
 * @copyright  Copyright (c) 2010 Steven Harris
 * @license    http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @version    $Id: FileAttributes.php 2 2010-02-07 04:10:51Z indigo.sunrise $
 */

/**
 * Represents the FileAttributes tag.
 *
 * @package    Pwiff
 * @subpackage Tags
 */
class Pwiff_Tag_FileAttributes extends Pwiff_Tag
{
	/**
	 * FileAttributes tag type.
	 *
	 * @var int
	 */
	protected $pwiffTag = 69;
	
	/**
	 * Flag to determine the use of hardware acceleration for blit operations.
	 * Always false for SWF < 10.
	 * 
	 * @var bool
	 */
	protected $useDirectBlit = false;
	
	/**
	 * Flag to determine the use of GPU compositing features when drawing
	 * graphics. Always false for SWF < 10.
	 *
	 * @var bool
	 */
	protected $useGpu = false;
	
	/**
	 * Flag to determine if the file has a metadata tag.
	 * 
	 * @var bool
	 */
	protected $useMetadata = false;
	
	/**
	 * Flag to determine if the file uses ActionScript 3. If false, uses
	 * ActionScript 1 or 2. Always false for SWF < 9.
	 *
	 * @var bool
	 */
	protected $useActionScript3 = false;
	
	/**
	 * Flag to determine if the file has network access, or only local access,
	 * when the SWF is loaded locally.
	 * 
	 * @var bool
	 */
	protected $useNetwork = false;
	
	/**
	 * Sets the "use direct blit" flag.
	 * 
	 * @param  bool $directBlit
	 * @return Pwiff_Tag_FileAttributes
	 */
	public function setUseDirectBlit($directBlit)
	{
		$this->useDirectBlit = $directBlit;
		return $this;
	}
	
	/**
	 * Sets the "use GPU" flag.
	 * 
	 * @param  bool $gpu
	 * @return Pwiff_Tag_FileAttributes
	 */
	public function setUseGpu($gpu)
	{
		$this->useGpu = $gpu;
		return $this;
	}
	
	/**
	 * Sets the "use metadata" flag, for if the file has a metadata tag.
	 * 
	 * @param  bool $metadata
	 * @return Pwiff_Tag_FileAttributes
	 */
	public function setUseMetadata($metadata)
	{
		$this->useMetadata = $metadata;
		return $this;
	}
	
	/**
	 * Sets the "use ActionScript 3" flag, if the file uses ActionScript 3
	 * rather than 1 or 2.
	 * 
	 * @param  bool $actionScript3
	 * @return Pwiff_Tag_FileAttributes
	 */
	public function setUseActionScript3($actionScript3)
	{
		$this->useActionScript3 = $actionScript3;
		return $this;
	}
	
	/**
	 * Sets the "use network" flag, if you want the file to have network access
	 * rather than local access, if the file is loaded locally.
	 * 
	 * @param  bool $network
	 * @return Pwiff_Tag_FileAttributes
	 */
	public function setUseNetwork($network)
	{
		$this->useNetwork = $network;
		return $this;
	}
	
	/**
	 * Checks if the "use direct blit" flag is set.
	 * 
	 * @return bool
	 */
	public function isUseDirectBlit()
	{
		return $this->useDirectBlit;
	}
	
	/**
	 * Checks if the "use GPU" flag is set.
	 * 
	 * @return bool
	 */
	public function isUseGpu()
	{
		return $this->useGpu;
	}
	
	/**
	 * Checks if the "use metadata" flag is set.
	 * 
	 * @return bool
	 */
	public function isUseMetadata()
	{
		return $this->useMetadata;
	}
	
	/**
	 * Checks if the "use ActionScript 3" flag is set.
	 * 
	 * @return bool
	 */
	public function isUseActionScript3()
	{
		return $this->useActionScript3;
	}
	
	/**
	 * Checks if the "use network" flag is set.
	 * 
	 * @return bool
	 */
	public function isUseNetwork()
	{
		return $this->useNetwork;
	}
	
	/**
	 * Gets the FileAttributes tag's length.
	 *
	 * @return int
	 */
	public function getTagLength()
	{
		// UB[32] = 4
		return 4;
	}
	
	/**
	 * Writes the FileAttributes tag to the given output instance.
	 *
	 * @param  Pwiff_Output $out
	 */
	public function write(Pwiff_Output $out)
	{
		$version = $this->pwiffEnv->getSwfVersion();
		
		parent::write($out); // write tag header
		$out->writeBits(0, 1); // reserved
		
		$out->writeBool($this->useDirectBlit AND ($version >= 10));
		$out->writeBool($this->useGpu AND ($version >= 10));
		$out->writeBool($this->useMetadata);
		$out->writeBool($this->useActionScript3 AND ($version >= 9));
		
		$out->writeBits(0, 2); // reserved
		
		$out->writeBool($this->useNetwork);
		
		$out->writeBits(0, 24); // reserved
	}
}
